import type { ComponentsConfig } from '../../types'
import globalComponents from './globalComponents'
// import globalSettings from './globalSettings'
import type { JsonSchema } from '@cms/json-schema-form'

interface IConfigs {
  // globalSettings: JsonSchema[]
  globalComponents: ComponentsConfig
  [k: string]: ComponentsConfig | JsonSchema[]
}

const configs: IConfigs = {
  globalComponents
  // globalSettings
}
const modules = (import.meta as any).globEager('./*.tsx')

Object.keys(modules).forEach((api) => {
  const key = api.replace('./', '').replace('.tsx', '')
  configs[key] = modules[api].default as ComponentsConfig
})

// const keys = []
// for (const c in configs) {
//   const a = configs[c] as ComponentsConfig
//   keys.push(...Object.keys(a.components ?? {}))
// }
// console.log(Array.from(new Set(keys)).join("'|'"))
export default configs
